package com.bw.zg3.Car

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.bw.base.entity.MessageEntity
import com.bw.base.entity.MessageEntityItem
import com.bw.base.net.ApiServer


class CarSure(val apiServer: ApiServer):PagingSource<Int,MessageEntityItem>(){
    override fun getRefreshKey(state: PagingState<Int, MessageEntityItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MessageEntityItem> {
        try {
            val i = params.key ?: 1
            val message = apiServer.getMessage("111122223333", 1)
            val i1 = if (message.data.size == 10) i + 1 else null
           return LoadResult.Page(message.data,null,i1)
        }catch (e:Exception){
           return LoadResult.Error(e)
        }


    }
}